#!/bin/bash

# 用户服务启动脚本

echo "=========================================="
echo "     IAS 用户服务启动脚本"
echo "=========================================="

# 设置环境变量（可根据实际情况修改）
export SERVER_PORT=18081

# MySQL主库配置
export MYSQL_MASTER_HOST=172.20.0.111
export MYSQL_MASTER_PORT=3306
export MYSQL_MASTER_DATABASE=ias_system
export MYSQL_MASTER_USERNAME=root
export MYSQL_MASTER_PASSWORD=123456

# MySQL从库配置
export MYSQL_SLAVE_HOST=172.20.0.111
export MYSQL_SLAVE_PORT=3306
export MYSQL_SLAVE_DATABASE=ias_system_read
export MYSQL_SLAVE_USERNAME=root
export MYSQL_SLAVE_PASSWORD=123456

# Redis配置
export REDIS_HOST=172.20.0.111
export REDIS_PORT=6379

# Nacos配置
export NACOS_SERVERS=172.20.0.112:8848
export NAME_SPACE=public
export NACOS_USERNAME=nacos
export NACOS_PASSWORD=nacos

echo "环境变量配置完成："
echo "- 服务端口: $SERVER_PORT"
echo "- MySQL主库: $MYSQL_MASTER_HOST:$MYSQL_MASTER_PORT/$MYSQL_MASTER_DATABASE"
echo "- MySQL从库: $MYSQL_SLAVE_HOST:$MYSQL_SLAVE_PORT/$MYSQL_SLAVE_DATABASE"
echo "- Redis: $REDIS_HOST:$REDIS_PORT"
echo "- Nacos: $NACOS_SERVERS"
echo ""

# 检查Maven是否安装
if ! command -v mvn &> /dev/null; then
    echo "错误：未找到Maven，请先安装Maven"
    exit 1
fi

# 检查Java版本
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
echo "Java版本: $java_version"

if [[ "$java_version" < "17" ]]; then
    echo "警告：建议使用Java 17或更高版本"
fi

echo ""
echo "开始启动用户服务..."
echo "访问地址："
echo "- 应用: http://localhost:$SERVER_PORT"
echo "- API文档: http://localhost:$SERVER_PORT/swagger-ui/index.html"
echo "- 健康检查: http://localhost:$SERVER_PORT/api/users/health"
echo ""

# 启动应用
mvn spring-boot:run 